package com.activenetwork.smlite.testcase.events.searchEvents;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.NoSuchElementException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;

import com.activenetwork.custom.uielement.UIElement;
import com.activenetwork.custom.uielement.decorate.IdentifierFactory;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.verification.gson.FailurePoint;

public class SearchEvents001 extends BaseCase {
	static final Logger logger = LoggerFactory.getLogger(SearchEvents001.class);
	
	@Test
	public void  UI_Verify_search_events_section_display(){
		loginBusiness.login();
		
		// Verify the event search section
		UIElement searchSection = null;
		try{
			searchSection = IdentifierFactory.createUIElement("EventsHomeView", "searchEventInput");
			
			String content = searchSection.getAttribute("placeholder").trim();
			if(!StringUtils.equals(content, "Search events")){
				EnvContext.failurePointTL.get().add(
						new FailurePoint(SearchEvents001.class.getName(), 
						"Verify event search section", 
						"Event search section default value is not " + "'Search events'"));
			}

		}catch(NoSuchElementException e){
			EnvContext.failurePointTL.get().add(
					new FailurePoint(SearchEvents001.class.getName(), 
					"Verify event search section", 
					"The search event section can not be found on the page"));
		}
		
		// Verify the search button
		UIElement button = null;
		try{
			button = IdentifierFactory.createUIElement("EventsHomeView", "searchButton");
		}catch(NoSuchElementException e){
			EnvContext.failurePointTL.get().add(
					new FailurePoint(SearchEvents001.class.getName(), 
					"Verify event search button", 
					"The search event button can not be found on the page"));
		}
		
		// verify the button should be right by the search section
		if(searchSection != null && button != null){
			int sectionX = searchSection.getLocation().getX();
			int sectionY = searchSection.getLocation().getY();
			System.out.println("Search section location X:"+sectionX+",Y:"+sectionY);
			int buttonX = button.getLocation().getX();
			int buttonY = button.getLocation().getY();
			System.out.println("Search button location X:"+buttonX+",Y:"+buttonY);
			
			if(sectionX >= buttonX && sectionY != buttonY){
				EnvContext.failurePointTL.get().add(
						new FailurePoint(SearchEvents001.class.getName(), 
						"Verify search section and button location", 
						"The search event button is not right by the search section"));
			}
			
		}
		
		loginBusiness.logout();
	}

}
